Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp_audio_shortcode() outputs invalid HTML #6917

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

shubham07kb
Copy link

wp_audio_shortcode() was chaging boolean attributes to 1, as of true === 1, in debug i notice it was directly happening after foreach, not by eascaping, so I have add a if statement to handle boolean attributes and directly pass our key, as Key can be directly work for boolean attributes in HTML.

Trac Ticket: https://core.trac.wordpress.org/ticket/61515

Copy link

github-actions bot commented Jun 27, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props shub07, dmsnell, narenin.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@shubham07kb shubham07kb changed the title Fix: wp_audio_shortcode, handle boolean attribute correctly in foreach wp_audio_shortcode() outputs invalid HTML Jun 27, 2024
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@narenin
Copy link

narenin commented Jun 27, 2024

Hi @shubham07kb

The PR looks good to me.

Copy link
Contributor

@dmsnell dmsnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like all this is doing is generating an HTML <audio> tag. What if instead of sticking with the old pattern and adjusting it for a very specific purpose, we replaced the generation with the use of the HTML API/

Is it correct that these values are the PHP boolean values true? If so, the HTML API will add them as boolean attributes, or if they are false, will automatically not add them.

$audio_tag_builder = new WP_HTML_Tag_Processor( '<audio controls>' );
$audio_tag_builder->next_tag();
foreach ( $html_attrs as $name => $value ) {
	$audio_tag_builder->set_attribute( $name, $value );
}

$html .= $audio_tag_builder->get_updated_html();

@shubham07kb shubham07kb requested a review from dmsnell July 2, 2024 03:52
@shubham07kb
Copy link
Author

Hi @dmsnell ,
Thank you for your feedback. I have implemented the suggested changes to utilize the HTML API for generating the tag. I agree that utilizing the internal HTML API is a better approach for generating the tag. It simplifies the code and efficiently handles boolean attributes.

@dmsnell
Copy link
Contributor

dmsnell commented Jul 2, 2024

@shubham07kb there are some existing tests for this in tests/phpunit/tests/media.php.
do you think you could add a new test covering this invalid boolean attribute behavior? and then verify that the test fails before applying your fix?

I guess it's worth stating that the boolean attributes with a value of "1" should actually still be true and semantically equivalent to their value-less counterparts. I'm sure a validator will say they are invalid, but behaviorally the existing code should have properly conveyed the boolean true nature of the attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants